<?php ob_start();
session_start(); //on relaye la session
if(isset($_SESSION["is_registered"]) && $_SESSION["is_registered"] == "registered"){
	$enregistrer = $_SESSION["is_registered"];
	$message="";
}else{
	header("Location:../../menu.php?erreur=intru"); // redirection en cas d'echec
}
$_SESSION['produit']=$_POST['val_sel'];

// script PHP interrogation Base de donnees pour reponse a la requette AJAX
require_once('../../Connections/microassur.php'); require_once('../../utils/fonctions.php'); 

include ("config.php");

// Connexion a la base de donnees  
	  mysql_select_db($database_microassur, $microassur);

$_SESSION['produit']=$_POST['val_sel'];
	$QuestionBase = "SELECT $champ1_Table3,$champ2_Table3 FROM $Table3  WHERE
	Date_debut_formule<='".$_GET['d']."' and (Date_fin_formule>='".$_GET['d']."' or  Date_fin_formule is NULL )  
	 and ".$champ1_Table2."='".$_POST['val_sel']."' ORDER BY ".$champ1_Table2." ASC " ;
	$result_recherche=mysql_query($QuestionBase, $microassur) or die (mysql_error());
	if(mysql_num_rows($result_recherche)>0) $_SESSION['produit']=$_POST['val_sel'];
	$requete=mysql_query("select * from produit where Identifiant_produit='".$_POST['val_sel']."'") or die(mysql_error());
	$reponse=mysql_fetch_array($requete);
	$offre=$reponse['Identifiant_offre'];
// construction de la liste deroulante
$aff="";$var1="";$var="";
$aff=$aff."<select name='formule' id='cont_list3' onFocus=\"makeRequest('rep_ajaxphp2.php?id1=".$_POST['val_sel']."&id2=".$offre."','cont_list3','id_list4')\"  onChange=\"makeRequest('rep_ajaxphp2.php?id1=".$_POST['val_sel']."&id2=".$offre."','cont_list3','id_list4')\"><option ".$var1.">-- Choisissez --</option>";


		 while ($row=mysql_fetch_assoc($result_recherche)){
		if( isset($_SESSION['formule']) && $row[$champ1_Table3]==$_SESSION['formule'])
		$var="selected='selected'";else
		 $var1="selected='selected'";
			$aff.="<option  ".$var."value=\"".$row[$champ1_Table3]."\">$row[$champ2_Table3]</option>"; 
		}
	$aff=$aff."</select>";
// envoi reponse Php a Ajax	
	echo $aff;
?>
<?php ob_end_flush();?>